Skip to content

Conversation

@jonathanhefner
Copy link

⚠️ Disclaimer: This was vibe-coded. I am not a PHP developer, but I am helping https://github.com/modelcontextprotocol/php-sdk set up documentation using phpDocumentor, and I encountered this issue. (See also modelcontextprotocol/php-sdk#232.) I guided Claude through the investigation and self-review, but I am unable to personally judge the fix.


Markdown links with both a page reference and a fragment anchor like [text](page-b.md#section-two) failed to resolve, producing a warning: "Reference page-b.md#section-two could not be resolved".

Two independent bugs caused this:

  1. LinkParser checked str_ends_with($url, '.md') on the full URL including the fragment, so page-b.md#section-two did not match and the .md extension was never stripped. Fix: split the fragment off before the .md check, then reattach it afterward.

  2. PageHyperlinkResolver passed the full target reference (including #fragment) to findDocumentEntry(), which always returned null since no document is keyed with a fragment suffix. Fix: split the fragment before the document lookup and append it to the generated URL, matching the pattern already used by DocReferenceResolver.

Markdown links with both a page reference and a fragment anchor like
`[text](page-b.md#section-two)` failed to resolve, producing a warning:
"Reference page-b.md#section-two could not be resolved".

Two independent bugs caused this:

1. `LinkParser` checked `str_ends_with($url, '.md')` on the full URL
   including the fragment, so `page-b.md#section-two` did not match and
   the `.md` extension was never stripped. Fix: split the fragment off
   before the `.md` check, then reattach it afterward.

2. `PageHyperlinkResolver` passed the full target reference (including
   `#fragment`) to `findDocumentEntry()`, which always returned `null`
   since no document is keyed with a fragment suffix. Fix: split the
   fragment before the document lookup and append it to the generated
   URL, matching the pattern already used by `DocReferenceResolver`.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant